package com.hmall.order.mq;

import com.hmall.order.pojo.Order;
import com.hmall.order.service.impl.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OrderMQListener {
    @Autowired
    OrderService orderService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue",durable = "true"),
            exchange =@Exchange(name="delay.order",delayed = "true"),
            key = "delay"
    ))
    public void listenOrder(String id){
        log.info("延迟队列的数据： {}",id);
        Order order = orderService.getById(Long.parseLong(id));
        if (order.getStatus()==1){
            order.setStatus(5);
            orderService.updateById(order);
        }
    }
}
